package com.espirit.init.biz;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Component;

import com.espirit.eap.manager.ModelBuilderSupport;
import com.espirit.eap.pagelayout.Element;
import com.espirit.eap.pagelayout.ModelField;
import com.espirit.hr.HrSetting;

@Component
public class HrSettingBuilder extends ModelBuilderSupport {
	static final String DATEFORMAT = "dateFormat";
//	static final String MAXLATEMINUTE ="punchInAfterMinutes";
//	static final String MAXLEAVEEARLYMINUTE ="punchOutBeforeMinutes";
	static final String CURRENT_ACCTTERM = "currentAcctTerm";
	static final String TOPMENU = "topMenu";
	static final String PAIDLEAVES = "paidLeaves";
	
	@Override
	public boolean init() {
		return super.setClass(HrSetting.class, "OperationSetting", "运营设置");
	}	

	@Override
	public void buildFields() {
		super.buildFields();
		addModelField(CURRENT_ACCTTERM, "Current AcctTerm", "当前会计期间");
		addModelField(DATEFORMAT, "Date format", "日期格式");
		addModelField(TOPMENU, "Top menu", "顶部菜单");
//		addModelField(MAXLATEMINUTE, "Max Late Min(m)", "最大迟到分钟");
//		addModelField(MAXLEAVEEARLYMINUTE, "Maxearlyleave Min(m)", "最大早退分钟");
		addModelField(PAIDLEAVES, "Paid Leave", "有偿请假");
	}
	
	@Override
	protected void setDefaultLayoutButtons() {
		super.setDefaultLayoutButtons();
	}
	
	@Override
	protected void addSearchFields() {
	}
	
	@Override
	protected void addListFields() {
	}
	
	@Override
	protected void addDetailFields() {
		addDetailField(convertPropertyToField(CURRENT_ACCTTERM, PAIDLEAVES, DATEFORMAT, TOPMENU));
	}
	
	@Override
	protected void gatherExproperties() {
		exProperties.put(REQUIRED, new String[]{CURRENT_ACCTTERM});
	}
	
	@Override
	protected Element convertFieldToElement(ModelField mf, boolean isListLayout) {
		Element element = super.convertFieldToElement(mf, isListLayout);
		String name = element.getName();
		if (!isListLayout){
			if (name.equals(PAIDLEAVES)){
				Map<String, String> exDataTypeProperties = new HashMap<String, String>();
				exDataTypeProperties.put("collection", "fn.service('espirit.hr.hrSetting').srcLeaveTypes");
				element.setExProperty(exDataTypeProperties);
				element.setTagName("checkbox");
				element.addExProperty("width", "500");
			}	
		}
		
		return element;
	}
	
}
